export function operate(num1,num2,operator){
    var newNum1 = num1 + ''
    var newNum2 = num2 + ''
    var num1DotIndex = newNum1.indexOf('.') 
    var num2DotIndex = newNum2.indexOf('.') 
    if(num1DotIndex === -1 && num2DotIndex === -1) { 
        return eval(num1 + operator + num2) 
    }
    if(num1DotIndex === -1){
        var num2Suffix = newNum2.slice(num2DotIndex+1)
        var max = num2Suffix.length
    }else if(num2DotIndex === -1){
        var num1Suffix = newNum1.slice(num1DotIndex+1)
        var max = num1Suffix.length
    }else{
        var num1Suffix = newNum1.slice(num1DotIndex+1)
        var num2Suffix = newNum2.slice(num2DotIndex+1)
        var max = num1Suffix.length
        if(num1Suffix.length < num2Suffix.length){
            max = num2Suffix.length
        }
    }

    
   
        var num1Zheng = num1 * Math.pow(10, max)
        var num2Zheng = num2 * Math.pow(10, max)
        switch(operator) { 
            case '+': 
            // 相加 
                var result = num1Zheng + num2Zheng 
            break 
            case '-': 
                var result = num1Zheng - num2Zheng 
            break 
            case '*': 
                var result = num1Zheng * num2Zheng 
                result /= Math.pow(10, max)
            break 
            case '/': 
                var result = num1Zheng / num2Zheng 
                result = +result.toFixed(2)
            break 
            default: 
                throw new Error('请输入正确的运算符')
        }
        return result / Math.pow(10, max)
    }
